<template>
  <div class="login">
    <div class="formLogin">
      <h2 class="title">VUE-ADMIN-MS</h2>
      <el-form
        :label-position="labelPosition"
        label-width="100px"
        :model="formLabelAlign"
        style="max-width: 500px"
      >
        <el-form-item label="用户名：">
          <el-input v-model="login.username" @keyup.enter="loginHandle" />
        </el-form-item>
        <el-form-item label="密码：">
          <el-input
            type="password"
            v-model="login.pwd"
            @keyup.enter="loginHandle"
          />
        </el-form-item>
      </el-form>
      <el-button class="submit" type="primary" @click="loginHandle">
        登录
      </el-button>
    </div>
    <div class="message">
      <div>账号 / 密码：admin / 123456</div>
      <div>账号 / 密码：jerry / 123456</div>
    </div>
  </div>
</template>

<script>
export default {
  name: "LoginPage",
  data() {
    return {
      login: {
        username: "admin",
        pwd: "123456",
      },
    };
  },
  methods: {
    loginHandle() {
      console.log("login", this.login);
      this.$store
        .dispatch("user/login", { username: this.login.username })
        .then(() => {
          // this.$route.query.redirect 登录成功后进入用户访问的页面
          this.$router.push({
            // path: this.$route.query.redirect || "/",
            path: "/",
          });
        })
        .catch((error) => {
          alert(error);
        });
    },
  },
};
</script>

<style>
.login {
  width: 100%;
  height: 100%;
  background: rgb(32, 112, 165);
}
.login .formLogin {
  width: 30%;
  min-width: 600px;
  height: 30%;
  min-height: 300px;
  margin: 0 auto;

  background: #fff;
  border-radius: 6px;
  position: relative;
  top: 30%;
}

.login .formLogin .title {
  padding: 24px 0;
}

.login .formLogin .submit {
  width: 50%;
  margin: 24px auto;
}

.message {
  width: 31%;
  color: #f3f3f3;
  margin: 0 auto;
  text-align: left;
  position: relative;
  top: 32%;
}

.message div {
  height: 25px;
  line-height: 25px;
}
</style>
